#include <bits/stdc++.h>

using namespace std;

int main() {

    map <string, int>  map_si = {{"yellow_cat", 1}, {"white_cat", 2}};
    map <int, int>     map_ii = {};

    cout << "===================== origin map_si =====================" << endl;
    cout << "map_si.size() = " << map_si.size() << endl;
    for (auto i = map_si.begin(); i != map_si.end(); i++) {
        cout << i->first << " " << i->second << endl;
    }

    /* =========================== step1 begin, map_si =========================== */
    cout << "===================== step1 begin, map_si =====================" << endl;

    map_si.insert(make_pair("black_cat", 3)); // 添加新的 "关键字-值" 对 (或称 key-value 对)
    map_si["blue_cat"] = 4;   // 添加新的 "关键字-值" 对 (或称 key-value 对)
    map_si["yellow_cat"] = 5; // 根据 "关键字" 修改值

    map_si.insert(make_pair("white_cat", 20)); // 添加 key-value 对失败! 因为已存在 "white_cat" 的关键字! 原有的 key-value 保持不变!

    cout << "map_si.size() = " << map_si.size() << endl;
    for (auto i = map_si.begin(); i != map_si.end(); i++) {
        cout << i->first << " " << i->second << endl;
    }
    cout << "===================== step1 end, map_si =====================" << endl;
    /* =========================== step1 end, map_si =========================== */

    /* =========================== step2, map_si =========================== */
    cout << "===================== step2 begin, map_si =====================" << endl;
    /*
      特别注意:
        下边这一行中, 由于当前 map_si 中不存在 "new_cat" 这样的关键字，将创建新的 key-value 对!
          map_si["new_cat"] = 0;
    */
    if (map_si["new_cat"] == 80) {
        cout << "map_si[\"new_cat\"] == 80" << endl;
    } else {
        cout << "map_si[\"new_cat\"] != 80, map_si[\"new_cat\"] == " << map_si["new_cat"] << endl;
    }

    /* 再次执行相同的语句时, 由于当前 map_si 中已存在 "new_cat" 这样的关键字, 所以不会判断新的 key-value 对! */
    if (map_si["new_cat"] == 0) {
        cout << "map_si[\"new_cat\"] == 0" << endl;
    } else {
        cout << "map_si[\"new_cat\"] != 0, map_si[\"new_cat\"] == " << map_si["new_cat"] << endl;
    }

    cout << "map_si.size() = " << map_si.size() << endl;
    for (auto i = map_si.begin(); i != map_si.end(); i++) {
        cout << i->first << " " << i->second << endl;
    }
    cout << "===================== step2 end, map_si =====================" << endl;
    /* =========================== step2 end, map_si =========================== */

    /* =========================== step3, map_si =========================== */
    cout << "===================== step3 begin, map_si =====================" << endl;
    // 判断 map_si 中是否存在 "white_cat" 关键字，如果存在则输出其对应的值(second)，不存在则输出 -1
    // 方法1: 使用 map_si.count() 方法
    if (map_si.count("white_cat") == 1){
        cout << map_si["white_cat"] << endl;
    }else{
        cout << -1 << endl;
    }

    // 方法2: 使用 map_si.find() 方法
    if (map_si.find("white_cat")!=map_si.end()){
        cout << map_si.find("white_cat") -> second << endl;
    }else{
        cout << -1 << endl;
    }

    map_si.clear();
    cout << "=== map_si.clear() ===" << endl;
    cout << "map_si.size() = " << map_si.size() << endl;
    cout << "===================== step3 end, map_si =====================" << endl;
    /* =========================== step3 end, map_si =========================== */

    /* =========================== step4, map_si =========================== */
    cout << "===================== step4 begin, map_si =====================" << endl;
    // 往 map_si 中添加 key-value 对
    map_si["little_cat"] = 1145;
    map_si.insert(make_pair("lihua_cat", 5));

    cout << "map_si.size() = " << map_si.size() << endl;
    for (auto i = map_si.begin(); i != map_si.end(); i++) {
        cout << i->first << " " << i->second << endl;
    }
    cout << "===================== step4 end, map_si =====================" << endl;
    /* =========================== step4 end, map_si =========================== */

    /* =========================== step1, map_ii =========================== */
    cout << "===================== map_ii =====================" << endl;
    cout << "map_ii.size() = " << map_ii.size() << endl;
    for (auto i = map_ii.begin(); i != map_ii.end(); i++) {
        cout << i->first << " " << i->second << endl;
    }

    return 0;
}